package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"question/models"
)

type TypeController struct {
	beego.Controller
}

type JsonR struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func (c *TypeController) Ask() {
	name := c.GetString("name")

	typed := models.QuestionType{
		Name: name,
	}

	err := models.DB.Create(&typed).Error
	if err != nil {
		c.Data["json"] = JsonR{
			Code: 0,
			Msg:  "添加失败",
			Data: nil,
		}
		c.ServeJSON()
	} else {
		c.Data["json"] = JsonR{
			Code: 200,
			Msg:  "添加成功",
			Data: nil,
		}
		c.ServeJSON()
	}
}
